package br.com.jk.uf;

import br.com.jk.master.Master;
import br.com.jk.util.Util;
import java.awt.event.KeyEvent;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import net.sf.jasperreports.engine.JRException;

/**
 *
 * @author camilo
 */
public class UfJDialog extends javax.swing.JDialog {

  private static UfJDialog dialog;
  // Model da tabela
  UfController ufcont = new UfController(this);
  UfTableModel ufTm = new UfTableModel();
  List<Uf> lstCid;
  private int idEnd;
  //Define se o Frame está sendo usado para consulta a partir de outro frame
  private boolean modoConsultaExt = false;
  private JTextField idPesquisa;
  private JTextField namePesquisa;

  //Singleton
  public static UfJDialog getInstance(java.awt.Frame parent, boolean modal) {
    if (dialog == null) {
      dialog = new UfJDialog(parent, modal);
    }
    return dialog;
  }

  public static UfJDialog getInstance(java.awt.Frame parent, boolean modal, JTextField id, JTextField name) {
    if (dialog == null) {
      dialog = new UfJDialog(parent, modal, id, name);
    }
    return dialog;
  }

  /**
   * Creates new form FornecedorJDialog
   */
  private UfJDialog(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();
    setLocationRelativeTo(null);
    listar();
  }

  /**
   * Contrutor para inicialização do JDialog no modo de consulta
   *
   * @param parent
   * @param modal
   * @param id
   * @param name
   */
  private UfJDialog(java.awt.Frame parent, boolean modal, JTextField id, JTextField name) {
    super(parent, modal);

    this.idPesquisa = id;
    this.namePesquisa = name;
    modoConsultaExt = true;

    initComponents();
    setLocationRelativeTo(null);
    listar();
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this
   * code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    JtbMaster = new javax.swing.JToolBar();
    JbNovo = new javax.swing.JButton();
    JbSalvar = new javax.swing.JButton();
    JbEditar = new javax.swing.JButton();
    JbCancelar = new javax.swing.JButton();
    JbExcluir = new javax.swing.JButton();
    JbBuscar = new javax.swing.JButton();
    JbRelatorio = new javax.swing.JButton();
    jSeparator1 = new javax.swing.JToolBar.Separator();
    JbRefresh = new javax.swing.JButton();
    jSeparator2 = new javax.swing.JToolBar.Separator();
    jScrollPane1 = new javax.swing.JScrollPane();
    jtUf = new javax.swing.JTable();
    jpDados = new javax.swing.JPanel();
    jLabel2 = new javax.swing.JLabel();
    jtfId = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jtfDescricao = new javax.swing.JTextField();
    jcbUf = new javax.swing.JComboBox();

    setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    setTitle("Cadastro de UF");
    setResizable(false);

    JtbMaster.setOrientation(javax.swing.SwingConstants.VERTICAL);
    JtbMaster.setRollover(true);

    JbNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-new.png"))); // NOI18N
    JbNovo.setToolTipText("Novo Registro");
    JbNovo.setFocusable(false);
    JbNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbNovo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbNovoActionPerformed(evt);
      }
    });
    JtbMaster.add(JbNovo);

    JbSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-save-hd.png"))); // NOI18N
    JbSalvar.setToolTipText("Salvar Registro");
    JbSalvar.setEnabled(false);
    JbSalvar.setFocusable(false);
    JbSalvar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbSalvar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbSalvar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbSalvarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbSalvar);

    JbEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/document-edit.png"))); // NOI18N
    JbEditar.setToolTipText("Alterar registro");
    JbEditar.setEnabled(false);
    JbEditar.setFocusable(false);
    JbEditar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbEditar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbEditar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbEditarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbEditar);

    JbCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/dialog-cancel.png"))); // NOI18N
    JbCancelar.setToolTipText("Cancelar");
    JbCancelar.setEnabled(false);
    JbCancelar.setFocusable(false);
    JbCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbCancelar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbCancelarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbCancelar);

    JbExcluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/archive-remove.png"))); // NOI18N
    JbExcluir.setToolTipText("Excluir");
    JbExcluir.setEnabled(false);
    JbExcluir.setFocusable(false);
    JbExcluir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbExcluir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbExcluir.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbExcluirActionPerformed(evt);
      }
    });
    JtbMaster.add(JbExcluir);

    JbBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/edit-find.png"))); // NOI18N
    JbBuscar.setToolTipText("Buscar");
    JbBuscar.setFocusable(false);
    JbBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbBuscar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbBuscarActionPerformed(evt);
      }
    });
    JtbMaster.add(JbBuscar);

    JbRelatorio.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/report.png"))); // NOI18N
    JbRelatorio.setToolTipText("Relatórios");
    JbRelatorio.setFocusable(false);
    JbRelatorio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbRelatorio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbRelatorio.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbRelatorioActionPerformed(evt);
      }
    });
    JtbMaster.add(JbRelatorio);
    JtbMaster.add(jSeparator1);

    JbRefresh.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/view-refresh.png"))); // NOI18N
    JbRefresh.setToolTipText("Atualizar registros da lista");
    JbRefresh.setFocusable(false);
    JbRefresh.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    JbRefresh.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
    JbRefresh.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        JbRefreshActionPerformed(evt);
      }
    });
    JtbMaster.add(JbRefresh);
    JtbMaster.add(jSeparator2);

    jtUf.setModel(ufTm);
    jtUf.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseClicked(java.awt.event.MouseEvent evt) {
        jtUfMouseClicked(evt);
      }
    });
    jtUf.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtUfKeyPressed(evt);
      }
    });
    jScrollPane1.setViewportView(jtUf);

    jpDados.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dados"));

    jLabel2.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel2.setText("Id");

    jtfId.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfId.setEnabled(false);
    jtfId.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfIdKeyPressed(evt);
      }
    });

    jLabel1.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jLabel1.setText("Descricao");

    jtfDescricao.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtfDescricao.setEnabled(false);
    jtfDescricao.addKeyListener(new java.awt.event.KeyAdapter() {
      public void keyPressed(java.awt.event.KeyEvent evt) {
        jtfDescricaoKeyPressed(evt);
      }
    });

    jcbUf.setFont(new java.awt.Font("Liberation Sans", 0, 14)); // NOI18N
    jcbUf.setEnabled(false);

    javax.swing.GroupLayout jpDadosLayout = new javax.swing.GroupLayout(jpDados);
    jpDados.setLayout(jpDadosLayout);
    jpDadosLayout.setHorizontalGroup(
      jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jpDadosLayout.createSequentialGroup()
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jtfId, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jLabel2))
        .addGap(2, 2, 2)
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(jpDadosLayout.createSequentialGroup()
            .addComponent(jtfDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, 249, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jcbUf, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
          .addComponent(jLabel1))
        .addContainerGap())
    );
    jpDadosLayout.setVerticalGroup(
      jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jpDadosLayout.createSequentialGroup()
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jLabel2)
          .addComponent(jLabel1))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(jpDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jtfId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jtfDescricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(jcbUf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addComponent(JtbMaster, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 387, Short.MAX_VALUE)
          .addComponent(jpDados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addContainerGap())
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(layout.createSequentialGroup()
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jpDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addComponent(JtbMaster, javax.swing.GroupLayout.PREFERRED_SIZE, 323, javax.swing.GroupLayout.PREFERRED_SIZE))
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void JbNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbNovoActionPerformed
    novo();
  }//GEN-LAST:event_JbNovoActionPerformed

  private void JbSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbSalvarActionPerformed
    salvar();
  }//GEN-LAST:event_JbSalvarActionPerformed

  private void JbEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbEditarActionPerformed
    editar();
  }//GEN-LAST:event_JbEditarActionPerformed

  private void JbCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbCancelarActionPerformed
    cancelar();
  }//GEN-LAST:event_JbCancelarActionPerformed

  private void JbExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbExcluirActionPerformed
    excluir();
  }//GEN-LAST:event_JbExcluirActionPerformed

  private void JbBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbBuscarActionPerformed
    pesquisar();
  }//GEN-LAST:event_JbBuscarActionPerformed

  private void JbRelatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbRelatorioActionPerformed
    try {
//      Master.setJpbStatusIndeterminate(true);
//      Master.setTextJlStatus("Gerando relatório...");
      ThreadReport thReport = new ThreadReport();
      thReport.start();

    } catch (Exception e) {
      Util.msgErro(e, "Erro ao gerar o relatório");
    }
  }//GEN-LAST:event_JbRelatorioActionPerformed

  private void JbRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JbRefreshActionPerformed
    listar();
  }//GEN-LAST:event_JbRefreshActionPerformed

  private void jtUfMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtUfMouseClicked
    if (ufTm.getRowCount() > 0 && (jtfId.getText() != null)) {
      HabilitaJb(true, false, true, false, true);
      HabilitaJtf(false);
      jtfId.setEditable(false);
      limpar();
      selecionado();
    }
  }//GEN-LAST:event_jtUfMouseClicked

  private void jtfIdKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfIdKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jtfDescricao.requestFocus();
    }
  }//GEN-LAST:event_jtfIdKeyPressed

  private void jtfDescricaoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtfDescricaoKeyPressed
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
      jcbUf.requestFocus();
    }
  }//GEN-LAST:event_jtfDescricaoKeyPressed

  private void jtUfKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jtUfKeyPressed
    if (modoConsultaExt) {
      ufcont.selecionarRegistro();
    }
  }//GEN-LAST:event_jtUfKeyPressed

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(UfJDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the dialog */
    java.awt.EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        UfJDialog dialog = new UfJDialog(new javax.swing.JFrame(), true);
        dialog.addWindowListener(new java.awt.event.WindowAdapter() {
          @Override
          public void windowClosing(java.awt.event.WindowEvent e) {
            System.exit(0);
          }
        });
        dialog.setVisible(true);
      }
    });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton JbBuscar;
  private javax.swing.JButton JbCancelar;
  private javax.swing.JButton JbEditar;
  private javax.swing.JButton JbExcluir;
  private javax.swing.JButton JbNovo;
  private javax.swing.JButton JbRefresh;
  private javax.swing.JButton JbRelatorio;
  private javax.swing.JButton JbSalvar;
  private javax.swing.JToolBar JtbMaster;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JToolBar.Separator jSeparator1;
  private javax.swing.JToolBar.Separator jSeparator2;
  private javax.swing.JComboBox jcbUf;
  private javax.swing.JPanel jpDados;
  private javax.swing.JTable jtUf;
  private javax.swing.JTextField jtfDescricao;
  private javax.swing.JTextField jtfId;
  // End of variables declaration//GEN-END:variables

  private void setJtUfTM(List<Uf> f) {
    while (ufTm.getRowCount() > 0) {
      ufTm.remove(0);
    }
    if (!f.isEmpty()) {
      ufTm.adicionaLista(f);
    }
  }

  private void novo() {
    limpar();
    HabilitaJb(false, true, false, true, false);
    HabilitaJtf(true);
    jtfDescricao.requestFocus();
    ufcont.listarUf();
  }

  private void salvar() {
    try {
      UfController cCont = new UfController(this);
      cCont.salvar();

      listar();
      HabilitaJb(true, false, false, false, false);
      HabilitaJtf(false);
      limpar();
    } catch (Exception e) {
      Util.msgErro(e, "Ocorreu erro ao tentar gravar no banco de dados");
    }
  }

  private void listar() {
    UfController fcont = new UfController(this);
    setJtUfTM(fcont.listar());
    fcont.listarUf();
  }

  private void limpar() {
    jtfId.setText(null);
    jtfDescricao.setText(null);
//    jcbUf.removeAllItems();
  }

  /**
   * Determina quais os botões da barra de ferramentas ficará ativo
   *
   * @param novo
   * @param salvar
   * @param editar
   * @param cancelar
   * @param excluir
   */
  private void HabilitaJb(Boolean novo, Boolean salvar, Boolean editar, Boolean cancelar,
          Boolean excluir) {
    JbNovo.setEnabled(novo);
    JbSalvar.setEnabled(salvar);
    JbEditar.setEnabled(editar);
    JbCancelar.setEnabled(cancelar);
    JbExcluir.setEnabled(excluir);
  }

  /**
   * Define se os JTextFields serão liberados para edição do usuário
   *
   * @param tf <b>True</b> - Habilitar; <b>False</b> - Desabilitar;
   */
  private void HabilitaJtf(Boolean tf) {
    jtfDescricao.setEnabled(tf);
    jcbUf.setEnabled(tf);
  }

  private void selecionado() {
    int linhaSel = jtUf.getSelectedRow();
    jtfId.setText(this.ufTm.getValueAt(linhaSel, UfTableModel.COLUNA_COD_ID).toString());
    jtfDescricao.setText(this.ufTm.getValueAt(linhaSel, UfTableModel.COLUNA_COD_DESCRICAO).toString());
    jcbUf.getModel().setSelectedItem(
            this.ufTm.getValueAt(linhaSel, UfTableModel.COLUNA_COD_NOME_UF).toString());
  }

  private void editar() {
    HabilitaJb(false, true, false, true, false);
    HabilitaJtf(true);
    jtfDescricao.requestFocus();
  }

  private void excluir() {
    UfController fcont = new UfController(this);
    fcont.excluir();
    listar();
    limpar();
  }

  private void cancelar() {
    limpar();
    HabilitaJb(true, false, false, false, false);
    HabilitaJtf(false);
    listar();
  }

  private void report() throws JRException, Exception {
    /*    FornecedorReport mReport = new FornecedorReport();
     mReport.geraRelatorio();
     Master.setTextJlStatus("");
     Master.setJpbStatusIndeterminate(false);*/
  }

  private void pesquisar() {
    HabilitaJb(false, false, false, true, false);
    jtfId.requestFocus();

    jtfId.setEnabled(true);
    jtfDescricao.setEnabled(true);
  }

  private void getLarguraJtBanco() {
    int grade;
    int column = ufTm.getColumnCount();
    //JtBanco.getColumnModel().getSelectedColumnCount();
    for (int i = 0; i < column; i++) {
      grade = this.jtUf.getColumnModel().getColumn(i).getPreferredWidth();
      System.out.println(grade);
    }
  }

  private void getPositionColumns() {
    System.out.println(jtUf.getColumnModel().getColumn(0).getHeaderValue());
  }

  class ThreadReport extends Thread {

    @Override
    public void run() {
      try {
        report();
      } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
      }
    }
  }

  public UfTableModel getCidTm() {
    return ufTm;
  }

  public void setCidTm(UfTableModel cidTm) {
    this.ufTm = cidTm;
  }

  public List<Uf> getLstCid() {
    return lstCid;
  }

  public void setLstCid(List<Uf> lstCid) {
    this.lstCid = lstCid;
  }

  public int getIdEnd() {
    return idEnd;
  }

  public void setIdEnd(int idEnd) {
    this.idEnd = idEnd;
  }

  public boolean isModoConsultaExt() {
    return modoConsultaExt;
  }

  public void setModoConsultaExt(boolean modoConsultaExt) {
    this.modoConsultaExt = modoConsultaExt;
  }

  public JTextField getIdPesquisa() {
    return idPesquisa;
  }

  public void setIdPesquisa(JTextField idPesquisa) {
    this.idPesquisa = idPesquisa;
  }

  public JTextField getNamePesquisa() {
    return namePesquisa;
  }

  public void setNamePesquisa(JTextField namePesquisa) {
    this.namePesquisa = namePesquisa;
  }

  public JButton getJbBuscar() {
    return JbBuscar;
  }

  public void setJbBuscar(JButton JbBuscar) {
    this.JbBuscar = JbBuscar;
  }

  public JButton getJbCancelar() {
    return JbCancelar;
  }

  public void setJbCancelar(JButton JbCancelar) {
    this.JbCancelar = JbCancelar;
  }

  public JButton getJbEditar() {
    return JbEditar;
  }

  public void setJbEditar(JButton JbEditar) {
    this.JbEditar = JbEditar;
  }

  public JButton getJbExcluir() {
    return JbExcluir;
  }

  public void setJbExcluir(JButton JbExcluir) {
    this.JbExcluir = JbExcluir;
  }

  public JButton getJbNovo() {
    return JbNovo;
  }

  public void setJbNovo(JButton JbNovo) {
    this.JbNovo = JbNovo;
  }

  public JButton getJbRefresh() {
    return JbRefresh;
  }

  public void setJbRefresh(JButton JbRefresh) {
    this.JbRefresh = JbRefresh;
  }

  public JButton getJbRelatorio() {
    return JbRelatorio;
  }

  public void setJbRelatorio(JButton JbRelatorio) {
    this.JbRelatorio = JbRelatorio;
  }

  public JButton getJbSalvar() {
    return JbSalvar;
  }

  public void setJbSalvar(JButton JbSalvar) {
    this.JbSalvar = JbSalvar;
  }

  public JToolBar getJtbMaster() {
    return JtbMaster;
  }

  public void setJtbMaster(JToolBar JtbMaster) {
    this.JtbMaster = JtbMaster;
  }

  public JLabel getjLabel1() {
    return jLabel1;
  }

  public void setjLabel1(JLabel jLabel1) {
    this.jLabel1 = jLabel1;
  }

  public JLabel getjLabel2() {
    return jLabel2;
  }

  public void setjLabel2(JLabel jLabel2) {
    this.jLabel2 = jLabel2;
  }

  public JScrollPane getjScrollPane1() {
    return jScrollPane1;
  }

  public void setjScrollPane1(JScrollPane jScrollPane1) {
    this.jScrollPane1 = jScrollPane1;
  }

  public JToolBar.Separator getjSeparator1() {
    return jSeparator1;
  }

  public void setjSeparator1(JToolBar.Separator jSeparator1) {
    this.jSeparator1 = jSeparator1;
  }

  public JToolBar.Separator getjSeparator2() {
    return jSeparator2;
  }

  public void setjSeparator2(JToolBar.Separator jSeparator2) {
    this.jSeparator2 = jSeparator2;
  }

  public JComboBox getJcbUf() {
    return jcbUf;
  }

  public void setJcbUf(JComboBox jcbUf) {
    this.jcbUf = jcbUf;
  }

  public JPanel getJpDados() {
    return jpDados;
  }

  public void setJpDados(JPanel jpDados) {
    this.jpDados = jpDados;
  }

  public UfController getUfcont() {
    return ufcont;
  }

  public void setUfcont(UfController ufcont) {
    this.ufcont = ufcont;
  }

  public UfTableModel getUfTm() {
    return ufTm;
  }

  public void setUfTm(UfTableModel ufTm) {
    this.ufTm = ufTm;
  }

  public JTable getJtUf() {
    return jtUf;
  }

  public void setJtUf(JTable jtUf) {
    this.jtUf = jtUf;
  }

  public JTextField getJtfDescricao() {
    return jtfDescricao;
  }

  public void setJtfDescricao(JTextField jtfDescricao) {
    this.jtfDescricao = jtfDescricao;
  }

  public JTextField getJtfId() {
    return jtfId;
  }

  public void setJtfId(JTextField jtfId) {
    this.jtfId = jtfId;
  }
}
